package com.neulogistics.core.substation.api.application.integrationevent.handler;

import com.blackto.lib.eventbus.abstraction.IIntegrationEventHandler;
import com.neulogistics.core.substation.api.application.integrationevent.subscribe.SubstationReturnInboundIntegrationEvent;
import com.neulogistics.core.substation.domain.model.aggregate.TaskOrder;
import com.neulogistics.core.substation.domain.model.enumeration.TaskStatus;
import com.neulogistics.core.substation.domain.repository.ITaskOrderRepository;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;

@Component
public class SubstationReturnInboundIntegrationEventHandler implements IIntegrationEventHandler<SubstationReturnInboundIntegrationEvent> {
    @Resource
    private ITaskOrderRepository taskOrderRepository;

    @Override
    public CompletableFuture<Void> handle(SubstationReturnInboundIntegrationEvent event) {
        TaskOrder taskOrder = taskOrderRepository.findById(event.taskId);
        taskOrder.setTaskStatus(TaskStatus.Completed);
        taskOrderRepository.save(taskOrder);

        return CompletableFuture.completedFuture(null);
    }
}
